package cn.yunlang.zhangZhongFei.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @Author：yff
 * @Package：com.yunlang.account.utils
 * @Project：applet-take-taxi
 * @name：PasswordUtil
 * @Date：2025/5/14 9:42
 */
public class PasswordUtil {

    // 将密码转换为SHA-256密文
    public static String hashPassword(String password) {
        try {
            MessageDigest digest = MessageDigest.getInstance("SHA-256");
            byte[] hashedBytes = digest.digest(password.getBytes());
            StringBuilder hexString = new StringBuilder();

            for (byte b : hashedBytes) {
                String hex = Integer.toHexString(0xff & b);
                if (hex.length() == 1) {
                    hexString.append('0');
                }
                hexString.append(hex);
            }
            return hexString.toString();
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
    }
}